home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1117 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: aril@cmt.lpr.mail.carel.fi (Ari Lukumies)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help with gettng 2 chars into an integer!
  5. Date: Thu, 11 Jan 1996 13:33:48 GMT
  6. Organization: Carelcomp Forest Oy
  7. Message-ID: <4d340d$kia@tahko.lpr.carel.fi>
  8. References: <4d2eh1$7pm@usc.edu>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. wawda@scf.usc.edu (Abu Wawda) wrote:
  13.  
  14.  
  15. >Hi. I can't seem to figure out how to do this. Basically I have to chars that 
  16. >I want to put into a 2-byte integer. It seems easy at first, but I can't seem 
  17. >to figure out to do it with the bit-fidling operators (shifting or masking). 
  18. >Simple put, I'd like to do:
  19.  
  20. >    char a,b;
  21. >    int c;
  22.  
  23. >    a = 'A';
  24. >    b = 'B';
  25. >    c = ? /* the first byte in c should contain the value of a, and the 
  26. >second byte should contain the value of b */
  27.  
  28. >Please help! Thanks in advance,
  29.  
  30. Try something like:
  31.  
  32.     #define    MAKEWORD(a, b)    (((int)a << 8) | (int)b)
  33.  
  34. Or, if you want them the other way around:
  35.  
  36.     #define    MAKEWORD(a, b)    (((int)b << 8) | (int)a)
  37.  
  38. Later,
  39. AriL
  40.  
  41. All my opinions are mine and mine alone.
  42.  
  43.